package com.wd.amodel.adapter;

import android.content.Context;

import androidx.fragment.app.FragmentActivity;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.chad.library.adapter.base.BaseMultiItemQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.wd.amodel.R;
import com.wd.amodel.bean.LinkageInfo;
import com.wd.base.util.Logger;

import java.util.ArrayList;
import java.util.List;

/**
 * NA<BR>
 *
 * @author w4425
 * @version [V2.0.0, 2021/4/26]
 * @since V2.0.0
 */
public class TabLinkageRvAdapter extends BaseMultiItemQuickAdapter<LinkageInfo, BaseViewHolder> {
    private Context context;
    private TabLinkageRvItemAdapter tabAdapter;

    /**
     * Same as QuickAdapter#QuickAdapter(Context,int) but with
     * some initialization data.
     *
     * @param data A new list is created out of this one to avoid mutable list
     */
    public TabLinkageRvAdapter(Context context, List<LinkageInfo> data) {
        super(data);
        this.context = context;
        addItemType(1, R.layout.item_linkage_info_list);
        addItemType(2, R.layout.item_linkage_info_text);
    }

    @Override
    protected void convert(BaseViewHolder helper, LinkageInfo item) {
        if (item == null) {
            Logger.w(TAG, "convert item == null");
            return;
        }
        switch (helper.getItemViewType()) {
            case 1:
                Logger.w(TAG, "convert");
                helper.setText(R.id.tv_title, item.title);

                List<String> list = new ArrayList<>();
                String url0 = "https://pics3.baidu.com/feed/4b90f603738da9772937bfd01959ba1f8618e33b.png?token=10c9af73b213298645482fe817869fca&s=160BD705927B779C000C4DB103002080";
                String url1 = "https://ss1.bdstatic.com/70cFuXSh_Q1YnxGkpoWK1HF6hhy/it/u=3118529426,2885674921&fm=26&gp=0.jpg";
                String url2 = "https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fdingyue.nosdn.127.net%2FGihVtrbCngePgSxCUg4GyJIF7g4mTyWZ2MD4gzbTZcSHH1535696417228.jpg&refer" +
                        "=http%3A%2F%2Fdingyue.nosdn.127.net&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=jpeg?sec=1614389139&t=f86b5df43fe20f13b954d989ce586b4d";
                list.add(url0);
                list.add(url1);
                list.add(url2);

                if (tabAdapter == null) {
                    tabAdapter = new TabLinkageRvItemAdapter((FragmentActivity) context, list);
                }
                RecyclerView mRv = helper.getView(R.id.recycler_view);
                // 设置布局方式
                RecyclerView.LayoutManager layoutManager = new LinearLayoutManager(context);
                mRv.setLayoutManager(layoutManager);
                mRv.setAdapter(tabAdapter);
                break;
            case 2:
                break;
            default:
                Logger.w(TAG, "default");
                break;
        }
    }
}
